/*
 *    This file is part of CeluMap.
 *
 *    CeluMap is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    CeluMap is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *    Copyright 2006, 2007, 2008 Gonzalo Merayo
 *    gonzalo (at) celumap.com.ar
 *    www.celumap.com.ar
 *
 */

package inputAdapter;
import java.io.DataOutputStream;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import map.file.FileConstants;
import map.file.FileMap;

public class MapGenerator {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String [] ss=new String[9];
		ss[0]="1.map";
		ss[1]="2.map";
		ss[2]="3.map";
		ss[3]="4.map";
		ss[4]="5.map";
		ss[5]="6.map";
		ss[6]="7.map";
		ss[7]="8.map";
		ss[8]="9.map";
		try {
			int cant = 10;
			generarMapa(ss[0], 0, 0, cant);
			generarMapa(ss[1], 0, 130, cant);
			generarMapa(ss[2], 130, 0, cant);
			generarMapa(ss[3], 130, 130, cant);
			
			OutputStream o = new FileOutputStream("indice.map");
			DataOutputStream os = new DataOutputStream(o);
			for(int i=0;i<ss.length;i++)
			{
				os.writeByte(FileConstants.FILE_TYPE_MAP);
				FileMap.writeString(os, ss[i]);
			}
			o.close();
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * @param origenX
	 * @param origenY
	 * @param cant
	 * @throws FileNotFoundException
	 * @throws IOException
	 */
	private static void generarMapa(String name, int origenX, int origenY, int cant) throws FileNotFoundException, IOException {
		OutputStream o = new FileOutputStream(name);
		DataOutputStream os = new DataOutputStream(o);
		int manzanaMasCalle = 12;
		int manzana = 10;
		os.writeByte(FileConstants.FILE_TYPE_MAP);//Mapa
		os.writeByte(FileConstants.ATTR_TYPE_AREA);//Area
		os.writeInt(origenX);
		os.writeInt(origenY);
		os.writeInt(origenX + cant*manzanaMasCalle);
		os.writeInt(origenY + cant*manzanaMasCalle);
		for(int k=0;k<cant;k++)//x
			for(int j=0;j<cant;j++)//y
			{
				int xIni = origenX + k*manzanaMasCalle;
				int yIni = origenY + j*manzanaMasCalle;
				os.writeByte(FileConstants.FIG_TYPE_LINE);os.writeInt(xIni);        os.writeInt(yIni);        os.writeInt(xIni);        os.writeInt(yIni+manzana);
				os.writeByte(FileConstants.FIG_TYPE_LINE);os.writeInt(xIni);        os.writeInt(yIni+manzana);os.writeInt(xIni+manzana);os.writeInt(yIni+manzana);
				os.writeByte(FileConstants.FIG_TYPE_LINE);os.writeInt(xIni+manzana);os.writeInt(yIni+manzana);os.writeInt(xIni+manzana);os.writeInt(yIni);
				os.writeByte(FileConstants.FIG_TYPE_LINE);os.writeInt(xIni+manzana);os.writeInt(yIni);        os.writeInt(xIni);        os.writeInt(yIni);
			}
		o.close();
	}

}
